import legacy from "@vitejs/plugin-legacy";
import react from "@vitejs/plugin-react";
import path, { resolve } from "path";
import { defineConfig } from "vite";
import svgr from "vite-plugin-svgr";
// https://vitejs.dev/config/
export default defineConfig({
  base: "./",
  plugins: [
    react(),
    svgr({ svgrOptions: { icon: true } }),
    legacy({
      targets: ["chrome 66"],
      additionalLegacyPolyfills: ["regenerator-runtime/runtime"],
      renderLegacyChunks: true,
      polyfills: [],
      modernPolyfills: [
        "es.symbol",
        "es.array.filter",
        "es.promise",
        "es.promise.finally",
        "es/map",
        "es/set",
        "es.array.for-each",
        "es.array.at",
        "es.array.flat-map",
        "es.object.define-properties",
        "es.object.define-property",
        "es.object.get-own-property-descriptor",
        "es.object.get-own-property-descriptors",
        "es.object.keys",
        "es.object.to-string",
        "web.dom-collections.for-each",
        "esnext.global-this",
        "esnext.string.match-all",
        "esnext.string.replace-all",
      ],
    }),
  ],
  assetsInclude: resolve(__dirname, "src/assets"),
  css: {
    devSourcemap: true,
    postcss: {
      plugins: [],
    },
  },
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
      "@@": path.resolve(__dirname, "src/hy_dev_lib/src"),
      hy_dev_lib: path.resolve(__dirname, "src/hy_dev_lib/src"),
    },
  },
  server: {
    port: 1111,
    proxy: {
      "/down": {
        //target: 'http://10.32.128.115:4016',
        target: "http://10.32.128.210:1235",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/down/, ""),
      },
    },

    // proxy: {
    //   '/api':{
    //     target: target,
    //     changeOrigin: true,
    //     pathRewrite: { '^/api': '' },
    //   },
    // },
  },
});
